package com.example.usingjsontocallwcf;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.example.Wcf.JSonFactory;

public class LoaiHang extends JSonFactory {
	

	
	public String Name;
	public List<MatHang>MatHangs;
	public LoaiHang()
	{
		
	}
	public LoaiHang(String name)
	{
		this.Name=name;
		List<MatHang>list=new ArrayList<MatHang>();
		for (int i = 0; i < 10; i++) {
			
			MatHang mHang=new MatHang("dsdsds");
			list.add(mHang);
		}
		this.MatHangs=list;
	}
	@Override
	public JSONObject toJson() {
		// TODO Auto-generated method stub
		JSONArray jsonArray=new JSONArray();
		for (MatHang mh : MatHangs) {
			
			jsonArray.put(mh.toJson());
		}
		JSONObject jsonObject=new JSONObject();
		try {
			jsonObject.put("Name", this.Name);
			jsonObject.put("MatHangs", jsonArray);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jsonObject;
	}
	
}
